package me.bincker.formwork.web.modules.system.entity

import com.fasterxml.jackson.annotation.JsonIgnore
import me.bincker.formwork.web.core.entity.BaseEntity
import me.bincker.formwork.web.core.entity.Nameable
import me.bincker.formwork.web.core.validated.ValidAdd
import javax.persistence.*
import javax.validation.constraints.NotEmpty

/**
 * 角色
 */
@Entity
class Role: BaseEntity(), Nameable {
    @NotEmpty(groups = [ValidAdd::class])
    override var name: String? = null

    @Column(unique = true, nullable = false)
    @NotEmpty(groups = [ValidAdd::class])
    var code: String? = null

    @ElementCollection
    var permissions: MutableSet<String>? = null

    @JsonIgnore
    @ManyToMany(fetch = FetchType.LAZY, mappedBy = "roleList")
    var userList: MutableSet<User>? = null
}